
/*
* Demo for Nacos
* pom.xml
    <dependency>
        <groupId>com.alibaba.nacos</groupId>
        <artifactId>nacos-client</artifactId>
        <version>${version}</version>
    </dependency>
*/
package com.disdr;

import java.util.Properties;
import com.alibaba.nacos.api.NacosFactory;
import com.alibaba.nacos.api.PropertyKeyConst;
import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.exception.NacosException;

/**
 * Config service example
 *
 * @author Nacos
 *
 */
public class ConfigExample {

    public static void main(String[] args) throws NacosException {
        String serverAddr = "121.43.237.14:8848";
        String dataId = "wedata-center-dev";
        String group = "java_group";
        Properties properties = new Properties();
        properties.put(PropertyKeyConst.SERVER_ADDR, serverAddr);
        properties.put(PropertyKeyConst.USERNAME, "datacenter");
        properties.put(PropertyKeyConst.PASSWORD, "datacentertest");
        //properties.put(PropertyKeyConst.CONTEXT_PATH,"/nacos");
        properties.put(PropertyKeyConst.NAMESPACE,"2a668cd3-6390-4a5b-bf2b-48dc4ab8a5aa");
        ConfigService configService = NacosFactory.createConfigService(properties);
        System.out.println(configService.getServerStatus());

        String content = configService.getConfig(dataId, group, 5000);

        System.out.println(content);
    }

    public static void main() throws NacosException, InterruptedException {
        String serverAddr = "tnacos.wegymer.com";
        String dataId = "wedata-pc-dev";
        String group = "java_group";
        Properties properties = new Properties();
        properties.put(PropertyKeyConst.SERVER_ADDR, serverAddr);
        properties.put(PropertyKeyConst.USERNAME, "nacos");
        properties.put(PropertyKeyConst.PASSWORD, "123456nacos");
        //properties.put(PropertyKeyConst.CONTEXT_PATH,"/");
        properties.put(PropertyKeyConst.NAMESPACE,"b0432ceb-373c-43a1-b354-885485ee850e");
        ConfigService configService = NacosFactory.createConfigService(properties);
        System.out.println(configService.getServerStatus());

        String content = configService.getConfig(dataId, group, 5000);

        System.out.println(content);

        /*configService.addListener(dataId, group, new Listener() {
            @Override
            public void receiveConfigInfo(String configInfo) {
                System.out.println("recieve:" + configInfo);
            }

            @Override
            public Executor getExecutor() {
                return null;
            }
        });*/

     /*   boolean isPublishOk = configService.publishConfig(dataId, group, "我是谁");
        System.out.println(isPublishOk);*/

      /*  Thread.sleep(3000);
        content = configService.getConfig(dataId, group, 5000);
        System.out.println(content);

        boolean isRemoveOk = configService.removeConfig(dataId, group);
        System.out.println(isRemoveOk);
        Thread.sleep(3000);

        content = configService.getConfig(dataId, group, 5000);
        System.out.println(content);
        Thread.sleep(300000);*/

    }
}
